﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Пятн
{
    public class Game2
    {
        public Form3 form;
        public int[] pos;

        public Game2(Form3 f3)
        {
            form = f3;
        } 

        public void Location1()
        {
            form.pictureBox1.Location = new Point(28, 34);
            form.pictureBox2.Location = new Point(134, 34);
            form.pictureBox3.Location = new Point(240, 34);
            form.pictureBox4.Location = new Point(346, 34);
            form.pictureBox5.Location = new Point(28, 140);
            form.pictureBox6.Location = new Point(134, 140);
            form.pictureBox7.Location = new Point(240, 140);
            form.pictureBox8.Location = new Point(346, 140);
            form.pictureBox9.Location = new Point(28, 246);
            form.pictureBox10.Location = new Point(134, 246);
            form.pictureBox11.Location = new Point(247, 246);
            form.pictureBox12.Location = new Point(346, 246);
            form.pictureBox13.Location = new Point(28, 352);
            form.pictureBox14.Location = new Point(134, 352);
            form.pictureBox15.Location = new Point(240, 352);
            form.pictureBox16.Location = new Point(247, 352);
        }

        public void Location2()
        {
            form.pictureBox1.Location = new Point(50, 50);
            form.pictureBox2.Location = new Point(150, 50);
            form.pictureBox3.Location = new Point(250, 50);
            form.pictureBox4.Location = new Point(350, 50);
            form.pictureBox5.Location = new Point(50, 150);
            form.pictureBox6.Location = new Point(150, 150);
            form.pictureBox7.Location = new Point(250, 150);
            form.pictureBox8.Location = new Point(350, 150);
            form.pictureBox9.Location = new Point(50, 250);
            form.pictureBox10.Location = new Point(150, 250);
            form.pictureBox11.Location = new Point(250, 250);
            form.pictureBox12.Location = new Point(350, 250);
            form.pictureBox13.Location = new Point(50, 350);
            form.pictureBox14.Location = new Point(150, 350);
            form.pictureBox15.Location = new Point(250, 350);
            form.pictureBox16.Location = new Point(350, 350);
        }
        
        public bool Analiz()
        {
            
            int i;
            for (i = 0; i < pos.Length; i++)
            {
                if (!(pos[i] == i + 1))
                    break;
            }
            if (i == pos.Length-1 && pos[pos.Length-1] == 0)
            {
                return true;
            }
            return false;
        }

        public void Move(int from, int clear)
        {
           switch(from)
           {
               case 1:
                   {
                       switch (clear)
                       {
                           case 2:
                               {
                                   form.pictureBox2.Image = form.pictureBox1.Image;
                                   form.pictureBox1.Image = form.empty.Image;
                                   form.clear = 1;
                                   pos[1] = pos[0];
                                   pos[0] = 0;
                               }
                               break;
                           case 5:
                               {
                                   form.pictureBox5.Image = form.pictureBox1.Image;
                                   form.pictureBox1.Image = form.empty.Image;
                                   form.clear = 1;
                                   pos[4] = pos[0];
                                   pos[0] = 0;
                               }
                               break;
                       }
                   }
                   break;
               case 2:
                 {
                     switch (clear)
                     {
                         case 1:
                             {
                                 form.pictureBox1.Image = form.pictureBox2.Image;
                                 form.pictureBox2.Image = form.empty.Image;
                                 form.clear = 2;
                                 pos[0] = pos[1];
                                 pos[1] = 0;
                             }
                             break;
                         case 3:
                             {
                                 form.pictureBox3.Image = form.pictureBox2.Image;
                                 form.pictureBox2.Image = form.empty.Image;
                                 form.clear = 2;
                                 pos[2] = pos[1];
                                 pos[1] = 0;
                             }
                             break;
                         case 6:
                             {
                                 form.pictureBox6.Image = form.pictureBox2.Image;
                                 form.pictureBox2.Image = form.empty.Image;
                                 form.clear = 2;
                                 pos[5] = pos[1];
                                 pos[1] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 3:
                 {
                     switch (clear)
                     {
                         case 2:
                             {
                                 form.pictureBox2.Image = form.pictureBox3.Image;
                                 form.pictureBox3.Image = form.empty.Image;
                                 form.clear = 3;
                                 pos[1] = pos[2];
                                 pos[2] = 0;
                             }
                             break;
                         case 4:
                             {
                                 form.pictureBox4.Image = form.pictureBox3.Image;
                                 form.pictureBox3.Image = form.empty.Image;
                                 form.clear = 3;
                                 pos[3] = pos[2];
                                 pos[2] = 0;
                             }
                             break;
                         case 7:
                             {
                                 form.pictureBox7.Image = form.pictureBox3.Image;
                                 form.pictureBox3.Image = form.empty.Image;
                                 form.clear = 3;
                                 pos[6] = pos[2];
                                 pos[2] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 4:
                 {
                     switch (clear)
                     {
                         case 3:
                             {
                                 form.pictureBox3.Image = form.pictureBox4.Image;
                                 form.pictureBox4.Image = form.empty.Image;
                                 form.clear = 4;
                                 pos[2] = pos[3];
                                 pos[3] = 0;
                             }
                             break;
                         case 8:
                             {
                                 form.pictureBox8.Image = form.pictureBox4.Image;
                                 form.pictureBox4.Image = form.empty.Image;
                                 form.clear = 4;
                                 pos[7] = pos[3];
                                 pos[3] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 5:
                 {
                     switch (clear)
                     {
                         case 1:
                             {
                                 form.pictureBox1.Image = form.pictureBox5.Image;
                                 form.pictureBox5.Image = form.empty.Image;
                                 form.clear = 5;
                                 pos[0] = pos[4];
                                 pos[4] = 0;
                             }
                             break;
                         case 6:
                             {
                                 form.pictureBox6.Image = form.pictureBox5.Image;
                                 form.pictureBox5.Image = form.empty.Image;
                                 form.clear = 5;
                                 pos[5] = pos[4];
                                 pos[4] = 0;
                             }
                             break;
                         case 9:
                             {
                                 form.pictureBox9.Image = form.pictureBox5.Image;
                                 form.pictureBox5.Image = form.empty.Image;
                                 form.clear = 5;
                                 pos[8] = pos[4];
                                 pos[4] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 6:
                 {
                     switch (clear)
                     {
                         case 2:
                             {
                                 form.pictureBox2.Image = form.pictureBox6.Image;
                                 form.pictureBox6.Image = form.empty.Image;
                                 form.clear = 6;
                                 pos[1] = pos[5];
                                 pos[5] = 0;
                             }
                             break;
                         case 5:
                             {
                                 form.pictureBox5.Image = form.pictureBox6.Image;
                                 form.pictureBox6.Image = form.empty.Image;
                                 form.clear = 6;
                                 pos[4] = pos[5];
                                 pos[5] = 0;
                             }
                             break;
                         case 7:
                             {
                                 form.pictureBox7.Image = form.pictureBox6.Image;
                                 form.pictureBox6.Image = form.empty.Image;
                                 form.clear = 6;
                                 pos[6] = pos[5];
                                 pos[5] = 0;
                             }
                             break;
                         case 10:
                             {
                                 form.pictureBox10.Image = form.pictureBox6.Image;
                                 form.pictureBox6.Image = form.empty.Image;
                                 form.clear = 6;
                                 pos[9] = pos[5];
                                 pos[5] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 7:
                 {
                     switch (clear)
                     {
                         case 3:
                             {
                                 form.pictureBox3.Image = form.pictureBox7.Image;
                                 form.pictureBox7.Image = form.empty.Image;
                                 form.clear = 7;
                                 pos[2] = pos[6];
                                 pos[6] = 0;
                             }
                             break;
                         case 6:
                             {
                                 form.pictureBox6.Image = form.pictureBox7.Image;
                                 form.pictureBox7.Image = form.empty.Image;
                                 form.clear = 7;
                                 pos[5] = pos[6];
                                 pos[6] = 0;
                             }
                             break;
                         case 8:
                             {
                                 form.pictureBox8.Image = form.pictureBox7.Image;
                                 form.pictureBox7.Image = form.empty.Image;
                                 form.clear = 7;
                                 pos[7] = pos[6];
                                 pos[6] = 0;
                             }
                             break;
                         case 11:
                             {
                                 form.pictureBox11.Image = form.pictureBox7.Image;
                                 form.pictureBox7.Image = form.empty.Image;
                                 form.clear = 7;
                                 pos[10] = pos[6];
                                 pos[6] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 8:
                 {
                     switch (clear)
                     {
                         case 4:
                             {
                                 form.pictureBox4.Image = form.pictureBox8.Image;
                                 form.pictureBox8.Image = form.empty.Image;
                                 form.clear = 8;
                                 pos[3] = pos[7];
                                 pos[7] = 0;
                             }
                             break;
                         case 7:
                             {
                                 form.pictureBox7.Image = form.pictureBox8.Image;
                                 form.pictureBox8.Image = form.empty.Image;
                                 form.clear = 8;
                                 pos[6] = pos[7];
                                 pos[7] = 0;
                             }
                             break;
                         case 12:
                             {

                                 form.pictureBox12.Image = form.pictureBox8.Image;
                                 form.pictureBox8.Image = form.empty.Image;
                                 form.clear = 8;
                                 pos[11] = pos[7];
                                 pos[7] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 9:
                 {
                     switch (clear)
                     {
                         case 5:
                             {
                                 form.pictureBox5.Image = form.pictureBox9.Image;
                                 form.pictureBox9.Image = form.empty.Image;
                                 form.clear = 9;
                                 pos[4] = pos[8];
                                 pos[8] = 0;
                             }
                             break;
                         case 10:
                             {
                                 form.pictureBox10.Image = form.pictureBox9.Image;
                                 form.pictureBox9.Image = form.empty.Image;
                                 form.clear = 9;
                                 pos[9] = pos[8];
                                 pos[8] = 0;
                             }
                             break;
                         case 13:
                             {
                                 form.pictureBox13.Image = form.pictureBox9.Image;
                                 form.pictureBox9.Image = form.empty.Image;
                                 form.clear = 9;
                                 pos[12] = pos[8];
                                 pos[8] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 10:
                 {
                     switch (clear)
                     {
                         case 6:
                             {
                                 form.pictureBox6.Image = form.pictureBox10.Image;
                                 form.pictureBox10.Image = form.empty.Image;
                                 form.clear = 10;
                                 pos[5] = pos[9];
                                 pos[9] = 0;
                             }
                             break;
                         case 9:
                             {
                                 form.pictureBox9.Image = form.pictureBox10.Image;
                                 form.pictureBox10.Image = form.empty.Image;
                                 form.clear = 10;
                                 pos[8] = pos[9];
                                 pos[9] = 0;
                             }
                             break;
                         case 11:
                             {
                                 form.pictureBox11.Image = form.pictureBox10.Image;
                                 form.pictureBox10.Image = form.empty.Image;
                                 form.clear = 10;
                                 pos[10] = pos[9];
                                 pos[9] = 0;
                             }
                             break;
                         case 14:
                             {
                                 form.pictureBox14.Image = form.pictureBox10.Image;
                                 form.pictureBox10.Image = form.empty.Image;
                                 form.clear = 10;
                                 pos[13] = pos[9];
                                 pos[9] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 11:
                 {
                     switch (clear)
                     {
                         case 7:
                             {
                                 form.pictureBox7.Image = form.pictureBox11.Image;
                                 form.pictureBox11.Image = form.empty.Image;
                                 form.clear = 11;
                                 pos[6] = pos[10];
                                 pos[10] = 0;
                             }
                             break;
                         case 10:
                             {
                                 form.pictureBox10.Image = form.pictureBox11.Image;
                                 form.pictureBox11.Image = form.empty.Image;
                                 form.clear = 11;
                                 pos[9] = pos[10];
                                 pos[10] = 0;
                             }
                             break;

                         case 12:
                             {
                                 form.pictureBox12.Image = form.pictureBox11.Image;
                                 form.pictureBox11.Image = form.empty.Image;
                                 form.clear = 11;
                                 pos[11] = pos[10];
                                 pos[10] = 0;
                             }
                             break;
                         case 15:
                             {
                                 form.pictureBox15.Image = form.pictureBox11.Image;
                                 form.pictureBox11.Image = form.empty.Image;
                                 form.clear = 11;
                                 pos[14] = pos[10];
                                 pos[10] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 12:
                 {
                     switch (clear)
                     {
                         case 8:
                             {
                                 form.pictureBox8.Image = form.pictureBox12.Image;
                                 form.pictureBox12.Image = form.empty.Image;
                                 form.clear = 12;
                                 pos[7] = pos[11];
                                 pos[11] = 0;
                             }
                             break;
                         case 11:
                             {
                                 form.pictureBox11.Image = form.pictureBox12.Image;
                                 form.pictureBox12.Image = form.empty.Image;
                                 form.clear = 12;
                                 pos[10] = pos[11];
                                 pos[11] = 0;
                             }
                             break;
                         case 16:
                             {
                                 form.pictureBox16.Image = form.pictureBox12.Image;
                                 form.pictureBox12.Image = form.empty.Image;
                                 form.clear = 12;
                                 pos[15] = pos[11];
                                 pos[11] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 13:
                 {
                     switch (clear)
                     {
                         case 9:
                             {
                                 form.pictureBox9.Image = form.pictureBox13.Image;
                                 form.pictureBox13.Image = form.empty.Image;
                                 form.clear = 13;
                                 pos[8] = pos[12];
                                 pos[12] = 0;
                             }
                             break;
                         case 14:
                             {
                                 form.pictureBox14.Image = form.pictureBox13.Image;
                                 form.pictureBox13.Image = form.empty.Image;
                                 form.clear = 13;
                                 pos[13] = pos[12];
                                 pos[12] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 14:
                 {
                     switch (clear)
                     {
                         case 10:
                             {
                                 form.pictureBox10.Image = form.pictureBox14.Image;
                                 form.pictureBox14.Image = form.empty.Image;
                                 form.clear = 14;
                                 pos[9] = pos[13];
                                 pos[13] = 0;
                             }
                             break;
                         case 13:
                             {
                                 form.pictureBox13.Image = form.pictureBox14.Image;
                                 form.pictureBox14.Image = form.empty.Image;
                                 form.clear = 14;
                                 pos[12] = pos[13];
                                 pos[13] = 0;
                             }
                             break;
                         case 15:
                             {
                                 form.pictureBox15.Image = form.pictureBox14.Image;
                                 form.pictureBox14.Image = form.empty.Image;
                                 form.clear = 14;
                                 pos[14] = pos[13];
                                 pos[13] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 15:
                 {
                     switch (clear)
                     {
                         case 11:
                             {
                                 form.pictureBox11.Image = form.pictureBox15.Image;
                                 form.pictureBox15.Image = form.empty.Image;
                                 form.clear = 15;
                                 pos[10] = pos[14];
                                 pos[14] = 0;
                             }
                             break;
                         case 14:
                             {
                                 form.pictureBox14.Image = form.pictureBox15.Image;
                                 form.pictureBox15.Image = form.empty.Image;
                                 form.clear = 15;
                                 pos[13] = pos[14];
                                 pos[14] = 0;
                             }
                             break;
                         case 16:
                             {
                                 form.pictureBox16.Image = form.pictureBox15.Image;
                                 form.pictureBox15.Image = form.empty.Image;
                                 form.clear = 15;
                                 pos[15] = pos[14];
                                 pos[14] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 16:
                 {
                     switch (clear)
                     {
                         case 12:
                             {
                                 form.pictureBox12.Image = form.pictureBox16.Image;
                                 form.pictureBox16.Image = form.empty.Image;
                                 form.clear = 16;
                                 pos[11] = pos[15];
                                 pos[15] = 0;
                             }
                             break;
                         case 15:
                             {
                                 form.pictureBox15.Image = form.pictureBox16.Image;
                                 form.pictureBox16.Image = form.empty.Image;
                                 form.clear = 16;
                                 pos[14] = pos[15];
                                 pos[15] = 0;
                             }
                             break;
                     }
                 }
                 break;

           }
        }
    }
}
